package com.haixiaoke.saas.enterprise.order.controller;

import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.annotation.TenantScope;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.order.domain.OrderStateRecord;
import com.haixiaoke.saas.order.service.IOrderStateRecordService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单状态变更记录Controller
 *
 * @author qixi
 * @date 2024-04-07
 */
@RestController
@RequestMapping("/enterprise/order/orderRecord")
public class EnterpriseOrderStateRecordController extends BaseController {
    @Autowired
    private IOrderStateRecordService orderStateRecordService;

    /**
     * 查询订单状态变更记录列表
     */
    // @PreAuthorize("@ss.hasPermi('order:orderRecord:list')")
    @GetMapping("/list")
    @TenantScope
    public TableDataInfo list(OrderStateRecord orderStateRecord) {
        startPage();
        List<OrderStateRecord> list = orderStateRecordService.selectOrderStateRecordList(orderStateRecord);
        return getDataTable(list);
    }

    /**
     * 导出订单状态变更记录列表
     */
    @PreAuthorize("@ss.hasPermi('order:orderRecord:export')")
    @Log(title = "订单状态变更记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderStateRecord orderStateRecord) {
        List<OrderStateRecord> list = orderStateRecordService.selectOrderStateRecordList(orderStateRecord);
        ExcelUtil<OrderStateRecord> util = new ExcelUtil<OrderStateRecord>(OrderStateRecord.class);
        util.exportExcel(response, list, "订单状态变更记录数据");
    }

    /**
     * 获取订单状态变更记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:orderRecord:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId) {
        return success(orderStateRecordService.selectOrderStateRecordByRecordId(recordId));
    }

    /**
     * 新增订单状态变更记录
     */
    @PreAuthorize("@ss.hasPermi('order:orderRecord:add')")
    @Log(title = "订单状态变更记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderStateRecord orderStateRecord) {
        return toAjax(orderStateRecordService.insertOrderStateRecord(orderStateRecord));
    }

    /**
     * 修改订单状态变更记录
     */
    @PreAuthorize("@ss.hasPermi('order:orderRecord:edit')")
    @Log(title = "订单状态变更记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderStateRecord orderStateRecord) {
        return toAjax(orderStateRecordService.updateOrderStateRecord(orderStateRecord));
    }

    /**
     * 删除订单状态变更记录
     */
    @PreAuthorize("@ss.hasPermi('order:orderRecord:remove')")
    @Log(title = "订单状态变更记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds) {
        return toAjax(orderStateRecordService.deleteOrderStateRecordByRecordIds(recordIds));
    }
}
